<script>

/**
 * Orders Component
 */
import Multiselect from "vue-multiselect";
export default {
  components: { Multiselect },
  data() {
    return {
      ordersData: [
        {
          name: "药物数据",
          customer: "东南大学",
          allnum: "129,875",
          onenum: "2,410",
          abnormalnum: "2,091",
          interfacenum: '18',
          creatTime: "2017/5/17"
        },
        {
          name: "债务人图谱",
          customer: "锦创科技股份有限公司",
          allnum: "6,687",
          onenum: "3,210",
          abnormalnum: "324",
          interfacenum: '22',
          creatTime: "2017/6/22"
        },
        {
          name: "资金流向系统",
          customer: "工商银行南京分行",
          allnum: "674",
          onenum: "4,321",
          abnormalnum: "24",
          interfacenum: '35',
          creatTime: "2018/5/17"
        },
        {
          name: "经济数据库",
          customer: "光大证券上海公司",
          allnum: "3,241",
          onenum: "321",
          abnormalnum: "55",
          interfacenum: '23',
          creatTime: "2018/7/12"
        },
        {
          name: "全网舆情",
          customer: "江苏省公安厅",
          allnum: "12,386",
          onenum: "1,241",
          abnormalnum: "125",
          interfacenum: '41',
          creatTime: "2019/5/7"
        },
        {
          name: "投顾分析系统",
          customer: "江苏百瑞赢投顾",
          allnum: "3,214",
          onenum: "8,761",
          abnormalnum: "241",
          interfacenum: '22',
          creatTime: "2020/11/24"
        },
        {
          name: "电网营销系统",
          customer: "南瑞集团",
          allnum: "209",
          onenum: "125",
          abnormalnum: "130",
          interfacenum: '21',
          creatTime: "2020/5/17"
        },
        {
          name: "企业运营管网",
          customer: "南京企运网",
          allnum: "52,133",
          onenum: "23,182",
          abnormalnum: "20",
          interfacenum: '32',
          creatTime: "2020/6/22"
        },
        {
          name: "大数据投顾系统",
          customer: "上海虑远",
          allnum: "43,153",
          onenum: "19,122",
          abnormalnum: "16",
          interfacenum: '27',
          creatTime: "2020/7/12"
        },
        {
          name: "企业贷销售线索挖掘",
          customer: "合肥人行",
          allnum: "46,178",
          onenum: "21,252",
          abnormalnum: "17",
          interfacenum: '24',
          creatTime: "2020/7/25"
        },
        {
          name: "企业贷销售线索挖掘",
          customer: "铜陵人行",
          allnum: "47,148",
          onenum: "21,552",
          abnormalnum: "18",
          interfacenum: '22',
          creatTime: "2020/8/06"
        },
        {
          name: "竞争态势感知",
          customer: "中国联通",
          allnum: "3,214",
          onenum: "331",
          abnormalnum: "211",
          interfacenum: '31',
          creatTime: "2020/8/17"
        },
        {
          name: "舆情监测",
          customer: "国家电网",
          allnum: "5,531",
          onenum: "3,210",
          abnormalnum: "132",
          interfacenum: '23',
          creatTime: "2020/9/19"
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "name", label: "项目名称" },
        { key: "customer", label: "对应客户" },
        { key: "allnum", label: "总计调用次数" },
        { key: "onenum", label: "当日调用次数" },
        { key: "abnormalnum", label: "异常次数" },
        { key: "interfacenum", label: "接口数量" },
        { key: "creatTime", label: "创建时间" },
        // { key: "viewDetail", label: "查看详情" },
      ],
      showModal: false,
      customerList: ['客户一','客户二'],
      customer: '',
      dataSourceList: ['数据源一','数据源二'],
      dataSource: '',
      entryName: '',
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发更新");
      }
    }
  },
  methods: {
    /**
     * Search the table data with search input
     */
    onFiltered(filteredItems) {
      // Trigger pagination to update the number of buttons/pages due to filtering
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    toRequestDetail(){
      this.$router.push('/interface/creatProject')
    },
    toDetail(){
      this.$router.push('/custom/detail')
      // let routeUrl = this.$router.resolve({
      //   path: '/custom/detail'
      // });
      // window.open(routeUrl.href, '_blank');
    },
    Search(){
      alert(this.searchinp)
    },
    tocreat(){
      let routeUrl = this.$router.resolve({
        path: '/interface/creatProject'
      });
      window.open(routeUrl.href, '_blank');
    },
    handleClose(){
      this.showModal = false
    },
  }
};
</script>

<template>
  <div>
    <!-- 搜索 -->
    <div class="search-box">
      <div class="search position-relative">
        <input type="text" @keyup.enter="Search" class="form-control" placeholder="请输入关键字" />
        <i class="mdi mdi-magnify search-icon"></i>
      </div>
    </div>
    <div class="allNum">
      <div class="searchNum">为您检索到<span>5,000+</span>条信息</div>
      <div>
        <b-dropdown dropup variant="secondary" class="butn">
          <template slot="button-content">
            <i class="ri-add-line align-middle" style="font-size: 1rem;"></i>
            <span style="margin:0 20px 0 6px;">接口管理</span>
            <i class="mdi mdi-chevron-up"></i>
          </template>
          <b-dropdown-item-button @click="tocreat">添加接口</b-dropdown-item-button>
          <b-dropdown-item-button @click="showModal=true">创建项目</b-dropdown-item-button>
        </b-dropdown>
      </div>
    </div>
    <div class="table-responsive">
      <b-table
        class="table-centered"
        :items="ordersData"
        :fields="fields"
        responsive="sm"
        :per-page="perPage"
        :current-page="1"
        thead-class="thead-light"
        @filtered="onFiltered"
      >
        <template v-slot:cell(name)="row">
          <a style="color: #5664d2;" @click="toRequestDetail(row.item)" target="_blank">{{row.value}}</a>
        </template>
        <template v-slot:cell(customer)="row">
          <a style="color: #5664d2;" @click="toDetail(row.item)" target="_blank">{{row.value}}</a>
        </template>
        <template v-slot:cell(abnormalnum)="row">
          <div class="badge font-size-12 badge-soft-danger">{{ row.value}}</div>
        </template>
        <!-- <template v-slot:cell(viewDetail)>
          <div>查看</div>
        </template> -->
      </b-table>
    </div>
    <div class="row">
      <div class="col">
        <div class="dataTables_paginate paging_simple_numbers float-right">
          <ul class="pagination pagination-rounded mb-0">
            <b-pagination v-model="currentPage" :total-rows="totalRows" :per-page="perPage"></b-pagination>
          </ul>
        </div>
      </div>
    </div>
    <el-dialog
      title="创建项目"
      :visible.sync="showModal"
      width="30%"
      :before-close="handleClose">
      <form>
        <div class="form-group">
          <label for="productname">客户</label>
          <multiselect
            v-model="customer"
            :options="customerList"
            placeholder="请选择客户"
          ></multiselect>
        </div>
        <div class="form-group">
          <label for="productname">数据源</label>
          <multiselect
            v-model="dataSource"
            :options="dataSourceList"
            placeholder="请选择数据源"
          ></multiselect>
        </div>
        <div class="form-group">
          <label for="productname">项目名称</label>
          <b-form-input
            for="text"
            v-model="entryName"
            placeholder="请输入项目名称"
          ></b-form-input>
        </div>
      </form>
      <span slot="footer" class="dialog-footer">
        <b-button style="margin-right:0.5rem;" variant="secondary" @click="showModal = false">关闭</b-button>
        <b-button variant="primary" @click="showModal = false">
          创建
          <i class="fab fa-telegram-plane ml-1"></i>
        </b-button>
      </span>
    </el-dialog>
  </div>
</template>
<style lang="scss" scoped>
.search {
  // float: left;
  width: 300px;
}
.butn{
  ::v-deep .btn{
    background-color: #252b3b;
    border-color: #252b3b;
    border-radius: 30px;
    display: flex;
    align-items: center;
  }
  ::v-deep .btn-secondary.focus {
    box-shadow: 0 0 0 0.15rem rgb(37 40 58 / 50%);
  }
}
.allNum{
  padding: 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchNum{
  span{
    font-size: 1rem;
    color: #3444c1;
    margin: 0 4px;
    font-weight: 600;
  }
}
.table-centered{
  ::v-deep thead,::v-deep tbody{
    tr{
      th:last-child,td:last-child{
        text-align: right;
      }
    }
  }
}
::v-deep .el-dialog__header,::v-deep .el-dialog__body{
  border-bottom: 1px solid #eeeeee;
}
</style>

